<?php

include_once ('soap_wsdl.php');

//global variable
$functions;
$servicerName;
$url;
$types;

class soap_server {

    public $wsdl;
    public $soapAddress;
    public $url;

    public function __construct($url) {
        $this->wsdl = new soap_wsdl($url);
        $this->url = $url;
    }

    public function register($nameProc, $description, $params, $return) {
        $input = array();
        foreach ($params as $name => $type) {
            $input[] = array("name" => $name, "type" => $type);
        }
        $output = array();
        foreach ($return as $name => $type) {
            $output[] = array("name" => $name, "type" => $type);
        }
        $this->wsdl->functions[] = array("funcName" => $nameProc,
            "doc" => $description,
            "inputParams" => $input,
            "outputParams" => $output,
            "soapAddress" => "http://" . $_SERVER['HTTP_HOST'] . "/index.php"
        );
    }

    public function service() {
        //generate wsdl
        $this->wsdl->configWSDL();
        ini_set("soap.wsdl_cache_enabled", "0");
        $server = new SoapServer(NULL, array("uri" => "wsdl.php"));
        //$server = new SoapServer('Libs/xmlsoap/soap_wsdl.wsdl');
        $server->setClass("mineServer");
        if (isset($_SERVER["REQUEST_METHOD"]) && $_SERVER["REQUEST_METHOD"] == "POST") {
            $server->handle();
        } else {
            if (isset($_SERVER["QUERY_STRING"]) && strcasecmp($_SERVER["QUERY_STRING"], "wsdl") == 0) {
                // Return the WSDL
                $wsdl = $this->wsdl->DisplayXML();
                //$wsdl = @implode ('', @file ('Libs/xmlsoap/soap_wsdl.wsdl'));
                if (strlen($wsdl) > 1) {
                    header("Content-type: text/xml");
                    echo $wsdl;
                } else {
                    header("Status: 500 Internal Server Error");
                    header("Content-type: text/plain");
                    echo "HTTP/1.0 500 Internal Server Error";
                }
            } else {
                //Some other non-related SOAP error
            }
        }
    }

}

?>